package com.showcai.web.controller.user;


import com.showcai.module.vo.User;
import com.showcai.tools.myRunTime.MyRunTimeExcption;
import com.showcai.web.service.UserServiceClient;
import com.showcai.webcore.controller.base.BaseController;
import feign.FeignException;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by Baggio on 2018-6-22.
 */
@Controller
@RequestMapping("user")
public class UserController extends BaseController {
    @Resource
    UserServiceClient userServiceClient;

    @RequestMapping(value = "/getUser",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String getUser() {
        System.out.println("dddddd");
        User user = null;
        try {
            user = userServiceClient.getUser(1l);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return user.getNickName();
    }

    @RequestMapping("/get/{id}")
    public ModelAndView user(@PathVariable("id") Long id) {
        System.out.println("user===================>>>>");
        ModelAndView mov = new ModelAndView();
        mov.setViewName("user/user.html");
        try {
            User   user = userServiceClient.getUser(id);
            System.out.println(user.getTid());
            System.out.println(user.getNickName());
     /*    PageInfo pageInfo= userServiceClient.getUserListPageInfo(new HashMap<String,String>());
            System.out.println(pageInfo.toString());
           List<User> list=pageInfo.getList();
            System.out.println(list.size());*/
/*      for (User user1:list){
          System.out.println(user1.toString())  ;
                System.out.println(user1.getTid());
                System.out.println(user1.getNickName());
                System.out.println(user1.getPhone());
            }*/
            mov.addObject("user", user);
        }catch (FeignException e) {
           logger.info(e.getMessage());
            e.printStackTrace();
        } catch (MyRunTimeExcption e) {
            logger.info(e.getMessage());
            e.printStackTrace();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        mov.addObject("title", "欢迎使用Thymeleaf!");
        return mov;
    }

    @RequestMapping(value = "/greeting")
    public ModelAndView test(ModelAndView mv) {
        mv.setViewName("/greeting.html");
        mv.addObject("title", "欢迎使用Thymeleaf!");
        return mv;
    }


}
